package star;

public class Utils {
    public static void swap(int[] arr, int i, int j){
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j]= temp;
    }

    public static void traversal(int[] arr){
        StringBuffer buffer = new StringBuffer();
        buffer.append("{");
        for (int i = 0; i < arr.length; i++) {
            buffer.append(arr[i]);
            if (i!= arr.length-1) buffer.append(",");
        }
        buffer.append("}");
        System.out.println(buffer.toString());
    }
    //异或运算,可以交换不同的数,可以交换相同的数,但是不能交换同一内存地址的数,否则两数清零.
    /*public static void swap(int[] arr, int i, int j){
        arr[i] = arr[i] ^ arr[j];
        arr[j] = arr[i] ^ arr[j];
        arr[i] = arr[i] ^ arr[j];
    }*/
}
